package com.family.gmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.family.gmall.model.user.UserInfo;
import com.family.gmall.user.mapper.UserInfoMapper;
import com.family.gmall.user.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import javax.annotation.Resource;

/**
 * @Auther: family
 * @Date: 2023/7/26 15:19
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfo login(UserInfo userInfo) {

        String passwd = userInfo.getPasswd();
        String newPassword = DigestUtils.md5DigestAsHex(passwd.getBytes());
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfo::getLoginName, userInfo.getLoginName());
        queryWrapper.eq(UserInfo::getPasswd, newPassword);
        UserInfo user = userInfoMapper.selectOne(queryWrapper);
        if (user != null) {
            return user;
        }
        return null;
    }
}
